/**
 * Copyright © 2021-2025 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.invoice.invoice.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jeeplus.invoice.invoice.domain.YxfpInvoice;
import com.jeeplus.invoice.invoice.mapper.YxfpInvoiceMapper;
import com.jeeplus.invoice.invoice.service.dto.YxfpInvoiceDTO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *  发票管理Service
 * @author 张如利
 * @version 2022-02-16
 */
@Service
@Transactional
public class YxfpInvoiceService extends ServiceImpl<YxfpInvoiceMapper, YxfpInvoice> {

	/**
	 * 根据id查询
	 * @param id
	 * @return
	 */
	public YxfpInvoiceDTO findById(String id) {
		return baseMapper.findById ( id );
	}

	/**
	 * 自定义分页检索
	 * @param page
	 * @param queryWrapper
	 * @return
	 */
	public IPage <YxfpInvoiceDTO> findPage(Page <YxfpInvoiceDTO> page, QueryWrapper queryWrapper) {
		queryWrapper.eq ("a.del_flag", 0 ); // 排除已经删除
		return  baseMapper.findList (page, queryWrapper);
	}
	/**
	 * 根据客户ID查询客户所开的发票列表数据
	 * @param customerId
	 * @return
	 */
	public List<YxfpInvoiceDTO> getInvoiceListByCustomerId(String customerId){
		return baseMapper.getInvoiceListByCustomerId(customerId);
	}

	/**
	 * 根据商户ID查询商户所开的发票列表数据
	 * @param merchantId
	 * @return
	 */
	public List<YxfpInvoiceDTO> getInvoiceListByMerchantId(String merchantId){
		return baseMapper.getInvoiceListByMerchanId(merchantId);
	}

	/**
	 * 根据商户ID和发票状态查询发票列表数据
	 * @param merchantId
	 * @param state
	 * @return
	 */
	public List<YxfpInvoiceDTO> getInvoiceListByMerchantIdAndState(String merchantId, String state) {
		return baseMapper.getInvoiceListByMerchantIdAndState(merchantId,state);
	}

	/**
	 * 根据客户ID和商户名称查询发票列表数据
	 * @param customerId
	 * @param merchantName
	 * @return
	 */
	public List<YxfpInvoiceDTO> getInvoiceListByCustomerIdAndMerchantName(String customerId,String merchantName){
		System.out.println("customerId="+customerId);
		System.out.println("merchantName="+merchantName);
		return baseMapper.getInvoiceListByCustomerIdAndMerchantName(customerId,merchantName);
	}
}
